All Questions
Tagged with design-patternsdependency-injection
125 questions
3votes
4answers
600views
Why is "dependency injection" ok, but not "the opposite of preserve whole object (pass required parameters only)"?
According to Why should I use dependency injection?, "dependency injection" has some advantages, for example: "Non dependency injection" version: public class Client{ private ...
3votes
2answers
570views
What value does the mediator pattern add beyond dependency injection?
Does the mediator pattern add any value beyond dependency injection? I am encountering the mediator pattern for the first time in context of this sample application, which is meant to demonstrate how ...
0votes
0answers
251views
better structure of a software project to prevent circular dependencies
I am contacting you today regarding a recent problem with circular dependencies. It's about a Spring boot application that accepts data via a Rest API and then forwards it to an internal Spring ...
0votes
3answers
438views
How to reconcile the fact that dependency Injection break encapsulation? (Especially when others are allowed to wire up your dependencies for you)
I was reading Martin Fowlers take on Dependency Injection, and in general have been trying to discuss it a bit online to help get rid of my own misconceptions and to understand this principle better. ...
3votes
4answers
299views
Please explain the "swapable dependency" arguments for IOC containers
I get that IOC containers can be useful to help break dependencies and allow you to test a class in isolation. I don't wish to focus on that right now, instead, I'm trying to understand some of the ...
1vote
3answers
477views
Why is Dependency Injection called "alternative of global state"?I think global state still exists
According to Why is Global State so Evil?, I believe we should avoid global state, so suppose I have an App that count user clicks in all pages like it: public class GlobalState{ public int ...
0votes
0answers
205views
How to handle dependency injection in a library to avoid frequent breaking changes?
Let's say I have a C# .NET library with the following classes: public class FooService { private readonly IDependencyA a; public FooService(IDependencyA a) { this.a = a; } ...
3votes
1answer
269views
Composite repositories: minimizing dependency injections
I have an application with dependency injection that consumes a REST API. The API calls are abstracted into entity-specific repositories. Some of the repositories are: HttpNotebookRepository, ...
1vote
2answers
205views
Why do we separate interface when implementing interface injection variant of DI?
With interface injection (wikpedia) we have a method to set the dependency on the client as part of an interfase. public interface ServiceSetter { public void setService(Service service); } Why ...
0votes
3answers
662views
Java Library - How to do Pure Dependency Injection When State is a Factor?
To set the stage, I am trying to do pure dependency injection for a Java Library I am creating to make it more testable. As it is a library, I want to do pure dependency injection without creating a ...
0votes
1answer
379views
Inject configuration files into the injector is it an antipattern?
I'm trying to design a system that inject configuration of each component into each class. project structure: |features --|component-a component-a.service.js component-a.config....
0votes
6answers
1kviews
If it is a bad practice to use an interface if only one class will implement it, what is the purpose of IoC container?
Okay, first of all I understand the concept of IoC container! It's used to implement automatic dependency injection so you won't have to manually inject dependencies to class. It can automatically ...
7votes
1answer
476views
Service Design Pattern
I'm working with services and I found out there are at least 3 ways to use them inside controllers... Statically: Like helper, Text::uppercase('foo') Instancing it: $text = new Text(); $text->...
4votes
1answer
961views
Dependency Injection: What are advantages of using a framework? [duplicate]
Introduction and Question I understand what the advantages of dependency injection, e.g. constructor injection or setter injection and that it is one way of doing inversion of control. I also ...
0votes
1answer
305views
Is it ok to Inject a whole object instead of only the dependencies
I'm working with the Dependency Injection Pattern in Unity3D (an engine which uses MonoBehavior, a class that doesn't have a constructor, as the base class for all of its game components), and I ended ...